<?php

namespace support;

/**
 * 单例工具类
 */
trait SingletonTrait
{
    // class instance container
    private static $instance = [];

    /**
     * 获取当前对象实例
     * @return static
     */
    public static function getInstance()
    {
        $className = get_called_class();
        $classNameMd5 = md5($className);
        if (is_null(self::$instance) || !isset(self::$instance[$classNameMd5])) {
            self::$instance[$classNameMd5] = new $className();
        }
        return self::$instance[$classNameMd5];
    }
}
